import { request } from 'umi';

/**
 * 角色列表
 * @param params
 * @param options
 * @returns
 */
export async function checkRoleList(options?: Record<string, any>) {
  return request<ADMIN.RoleAll>('/v1/roles/all', {
    method: 'GET',
    ...(options || {}),
  });
}

/**
 * 角色table列表
 */
export async function listRole(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
    remark?: string;
    name?: string;
  },
  options?: Record<string, any>,
) {
  return request<ADMIN.RoleList>('/v1/roles', {
    method: 'GET',
    params: { ...params },
    ...(options || {}),
  });
}

/**
 * 新建角色
 */
export async function addRole(body: ADMIN.Role, options?: Record<string, any>) {
  return request<ADMIN.Role>('/v1/role/create', {
    method: 'POST',
    data: {
      ...body,
    },
    ...(options || {}),
  });
}

/**
 * 修改角色
 */
export async function editRole(
  id: number | undefined,
  body: ADMIN.Role,
  options?: Record<string, any>,
) {
  return request<ADMIN.Role>('/v1/role/edit/' + id, {
    method: 'PUT',
    data: {
      ...body,
    },
    ...(options || {}),
  });
}

/**
 * 删除角色
 * @param id
 * @param options
 * @returns
 */
export async function deleteRole(id: number | undefined, options?: Record<string, any>) {
  return request<ADMIN.Success>('/v1/role/delete/' + id, {
    method: 'DELETE',
    ...(options || {}),
  });
}
